package com.bmt.pos.dao;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.bmt.core.BaseDao;
import com.bmt.pos.bean.User;


@Repository("userDao")
public class UserDao extends BaseDao{

	public User addUser(final User sUser){
		  sUser.setId(super.saveAndReturnKey(sUser).intValue());
		  return sUser; 
	}
	


	public List<User> getUsers() {
		return getJdbcTemplate().query("select *  from sys_user where active=1 ", new BeanPropertyRowMapper<User>(User.class));
	}
	public User getUserByColunm(String columnName, Object value) {
		return getJdbcTemplate().queryForObject("select *  from sys_user where active=1 and "+columnName+"=?", new BeanPropertyRowMapper<User>(User.class),value);
	}
	
	public List<User> getUsersByPage(int pageNum, int pageSize) {
		return getJdbcTemplate().query("select *  from sys_user where active=1 order by id limit ?, ?", new BeanPropertyRowMapper<User>(User.class),pageNum,pageSize);
	}

	/**
	 * 获得User记录总数
	 * @return
	 */
	@Override
	public int getDataTotal() {
		return  getJdbcTemplate().queryForInt("select count(*) from sys_user where active=1");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User> getDataByPage(int pageNum, int pageSize) {
		return getJdbcTemplate().query("select *  from sys_user where active=1 order by id limit ?, ?", new BeanPropertyRowMapper<User>(User.class),pageNum,pageSize);
	}



	
}
